package game;


import org.newdawn.slick.*;

/**
 * GUI des Startmenüs
 * 
 * <br /><br />Auskommentierte Codezeilen beziehen sich auf die Netwerkfähigkeit und werden nicht benötigt.
 * 
 * @author mariuswi
 */
public class GuiStartmenu {
    
    //Attribute
    int screenWidth;
    int screenHeight;
    
        //Attribute Resources--------------
         Image img_back;
//         Image img_server;
//         Image img_connect;
         Image img_finish;
         Image img_2player;
         Image img_3player;
         //Rechtecke zur Maus-Klick erkennung
//         Rectangle rec_server;
//         Rectangle rec_connect;
         Rectangle rec_finish;
         Rectangle rec_2player;
         Rectangle rec_3player;
        
    //Konstruktor
    GuiStartmenu() throws SlickException{
        
         // Laden der Ressourcen
        Color color = new Color(0xFF77FFFF); //Transparente Farbe
        this.img_back = new Image("res/background_menu.jpg");
//        this.img_server = new Image("res/menu_server.png",color);
//        this.img_connect = new Image("res/menu_connect.png", color);
        this.img_finish = new Image("res/menu_ende.png", color);
        this.img_2player = new Image("res/menu_2player.png", color);
        this.img_3player = new Image("res/menu_3player.png", color);
                
    }
    //Methoden     
    
    /**
     * Initialisiert das Startmenü. Setzt Bildschirmgröße und Menüpunkte.
     * 
     * @param app
     * @throws SlickException Falls setzen des Displaymodes fehlschlägt.
     */
    public void init(AppGameContainer app) throws SlickException{
        this.screenHeight = 600;
        this.screenWidth = 800;
        
        app.setDisplayMode(screenWidth, screenHeight, false);
        
        //Einstellen der ButtonBereiche entsprechen der Fenstergrößen
        this.rec_finish = new Rectangle((this.screenWidth/2),
                                            (this.screenHeight/3)-(this.screenHeight/5)+ 3 * this.img_finish.getHeight() + 5,
                                            this.img_finish.getWidth(),
                                            this.img_finish.getHeight());
//        this.rec_connect = new Rectangle((this.screenWidth/2),
//                                            (this.screenHeight/3)-(this.screenHeight/5)+ 2 * this.img_connect.getHeight() + 5,
//                                             this.img_connect.getWidth(),
//                                             this.img_connect.getHeight());
//        this.rec_server = new Rectangle((this.screenWidth/2),
//                                            (this.screenHeight/3)-(this.screenHeight/5)+ 1 * this.img_server.getHeight() + 5,
//                                            this.img_server.getWidth(),
//                                            this.img_server.getHeight());
        this.rec_2player = new Rectangle((this.screenWidth/2),
                                            (this.screenHeight/3)-(this.screenHeight/5)- 1 * this.img_2player.getHeight() + 5,
                                            this.img_2player.getWidth(),
                                            this.img_2player.getHeight());
        this.rec_3player = new Rectangle((this.screenWidth/2),
                                            (this.screenHeight/3)-(this.screenHeight/5)- 0 * this.img_3player.getHeight() + 5,
                                            this.img_3player.getWidth(),
                                            this.img_3player.getHeight());
        
    }
    
    /**
     * Rendert alle klickbaren Objekte. Bewegt die Menüpunkte beim Drüberfahren.
     * 
     * @param container
     * @param g 
     */
    public void render(GameContainer container, Graphics g){
        
        img_back.draw(0,0,0.65f); //Hintergrund im scale 0.65 im Vergleich zum Original laden
              
        Input input = container.getInput();
        int mouseX = input.getMouseX();
        int mouseY = input.getMouseY();
        
        //Animation der Buttons und rendering der Buttons
        //Button Server erstellen
//        if(this.rec_server.isInside(mouseX, mouseY)){
//            img_server.draw(this.rec_server.getTopx()+10, this.rec_server.getTopy());
//        }else{
//            img_server.draw(this.rec_server.getTopx(), this.rec_server.getTopy());
//        }
        //Button Server verbinden
//        if(this.rec_connect.isInside(mouseX, mouseY)){
//            img_connect.draw(this.rec_connect.getTopx()+10, this.rec_connect.getTopy());
//        }else{
//            img_connect.draw(this.rec_connect.getTopx(), this.rec_connect.getTopy());
//        }
        //Button Spiel beenden
        if(this.rec_finish.isInside(mouseX, mouseY)){
            img_finish.draw(this.rec_finish.getTopx()+10, this.rec_finish.getTopy());
        }else{
            img_finish.draw(this.rec_finish.getTopx(), this.rec_finish.getTopy());
        }
        //Button 2 Spieler Game
        if(this.rec_2player.isInside(mouseX, mouseY)){
            img_2player.draw(this.rec_2player.getTopx()+10, this.rec_2player.getTopy());
        }else{
            img_2player.draw(this.rec_2player.getTopx(), this.rec_2player.getTopy());
        }
        //Button 3 Spieler Game
        if(this.rec_3player.isInside(mouseX, mouseY)){
            img_3player.draw(this.rec_3player.getTopx()+10, this.rec_3player.getTopy());
        }else{
            img_3player.draw(this.rec_3player.getTopx(), this.rec_3player.getTopy());
        }
    }
    
    /**
     * Handelt Nutzereingaben. Startet einzelne Spiele oder beendet das Spiel.
     * 
     * @param container
     * @param c
     * @throws SlickException 
     */
     public void update(GameContainer container, GameControl c) throws SlickException{
        Input input = container.getInput();
        int mouseX = input.getMouseX();
        int mouseY = input.getMouseY();
        
        //On Mausklick---------------------------------
        if(input.isMouseButtonDown(input.MOUSE_LEFT_BUTTON)){
            //Button 2 Spieler Game starten
            if(this.rec_2player.isInside(mouseX, mouseY)){
                c.incomingInput(new CInput(CInput.TWOPLAYER));
            }
        
            //Button Spiel beenden
            if(this.rec_finish.isInside(mouseX, mouseY)){
                c.incomingInput(new CInput(CInput.EXIT));
            }
            //Button 3 Spieler Game starten
            if(this.rec_3player.isInside(mouseX, mouseY)){
                c.incomingInput(new CInput(CInput.THREEPLAYER));
            }
            
        }       
    }
}
